package com.itheima.ydd.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.ydd.commom.R;
import com.itheima.ydd.dto.YddAdvimgDto;

import com.itheima.ydd.dto.YddAdvposDto;
import com.itheima.ydd.entity.YddAdvimg;
import com.itheima.ydd.entity.YddAdvpos;
import com.itheima.ydd.service.YddAdvimgService;
import com.itheima.ydd.service.YddAdvposService;
import com.itheima.ydd.utils.PageUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@RestController()
@RequestMapping("ydd_advimg")
public class YddAdvimgController {
    @Autowired
    YddAdvimgService yddAdvimgService;

    @Autowired
    private YddAdvposService yddAdvposService;

    //修改广告图数据回显
    @GetMapping("rowInfo")
    public R rowInfo(int id) {
        YddAdvimg yddAdvimg = yddAdvimgService.getById(id);
        return R.success("", yddAdvimg);
    }

    @GetMapping("list")
    public R list(String advimgdesc, String advimgpos, int page, int limit) {
        PageUtils<YddAdvimgDto> pageInfo = yddAdvimgService.getPage(advimgdesc, advimgpos, page, limit);
        return R.success("", pageInfo);
    }

    //更新广告图
    @PostMapping("update")
    public R update(@RequestBody YddAdvimg yddAdvimg) {
        yddAdvimgService.updateById(yddAdvimg);
        return R.success("", "");
    }

    //添加广告图
    @PostMapping("add")
    public R add(@RequestBody YddAdvimg yddAdvimg) {
        yddAdvimgService.save(yddAdvimg);
        return R.success("", "");
    }

    //删除广告图
    @GetMapping("del")
    public R delete(Integer id) {
        yddAdvimgService.removeById(id);
        return R.success("", "");
    }
}
